package com.anlu.base.common.feign.core;

import com.anlu.base.common.core.constant.SecurityConstants;
import com.anlu.base.common.feign.annotation.NoToken;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.core.Ordered;

import java.lang.reflect.Method;

public class PigFeignInnerRequestInterceptor implements RequestInterceptor, Ordered {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        Method method = requestTemplate.methodMetadata().method();
        NoToken noToken = method.getAnnotation(NoToken.class);
        if (noToken != null) {
            requestTemplate.header(SecurityConstants.FROM, SecurityConstants.FROM_IN);
        }
    }

    @Override
    public int getOrder() {
        return Integer.MIN_VALUE;
    }
}
